package com.jgp.glmeeting.controller;

import com.jgp.glmeeting.model.Manager;

import com.jgp.glmeeting.service.ManagerService;

import com.jgp.security.admin.model.AdminUser;
import com.jgp.security.admin.service.AdminUserService;
import com.jgp.sys.common.controller.JGPController;
import com.jgp.sys.ui.GridResult;
import com.jgp.sys.ui.Pager;
import com.jgp.sys.ui.Result;
import com.jgp.sys.ui.annotation.UIParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/glMeeting/managerApiController")
public class ManagerApiController extends JGPController {
    @Autowired
    private ManagerService managerService;

    @Autowired
    private AdminUserService adminUserService;

    //处理会议总管所有和分页
    @RequestMapping("/queryManager")
    public Result queryManager(Manager m, @UIParam("pager") Pager pager){
        List<Manager> lists=managerService.queryManager(m,pager);
        List<GridResult.Category> categories = new ArrayList<>();
        categories.add(new GridResult.Category(  "姓名",  "name"));

        categories.add(new GridResult.Category("联系电话",  "mobilePhone"));
        categories.add(new GridResult.Category("身份证号",  "cardNo"));


        return ajaxRe("gdata",categories,lists,pager);
    }
    //添加会议总管
    @RequestMapping("/addManager")
    public Result addManager(Manager m){
        AdminUser a=new AdminUser();
        a.setUsername(m.getName());
        a.setPassword("123");

                m.setAdminUserID(  adminUserService.createUser(a).getId());
        managerService.addManager(m);
        return ajaxRe(true);
    }
    //编辑会议总管
    @RequestMapping("/editManager")
    public Result editManager(Manager m){

        managerService.addManager(m);
        return ajaxRe(true);
    }
    //删除会议总管
    @RequestMapping("/removeManager")
    public Result removeManager(String id){
        managerService.removeManager(id);
        return ajaxRe(true);
    }
}
